import pandas as pd
from selenium import webdriver
import time

p = int(10)


def re_(html, datafile=None):
    if datafile is None:
        datafile = []
    import re
    a_ = re.compile("""<h3 data-v-7c5c0928="" class="m-t-sm m-b-xs name">(.*?)</h3>""")
    b_ = re.compile("""<p data-v-7c5c0928="" class="authors">(.*?)</p>""")
    a = a_.findall(html)
    b = b_.findall(html)
    for i_ in zip(a, b):
        datafile.append(i_)
    return datafile


def http_requests(i=int(1)):
    one_or_twq = 0
    while i < p:
        Url = f"https://spa5.scrape.center/page/{i}"
        client.get(Url)
        time.sleep(3)
        i += int(1)
        html = client.page_source
        datafile = re_(html)
        df = pd.DataFrame(datafile)
        print(datafile)
        if one_or_twq == 0:
            df.to_csv("main.csv", mode='a', index=False)
            one_or_twq = 1
        else:
            df.to_csv("main.csv", mode='a', index=False, header=False)
    return


if __name__ == "__main__":
    client = webdriver.Chrome()
    http_requests()
    client.close()
